<template>
	<div class="common_tabs_container">
		<el-tabs type="card" class="custom_top" v-model="activeName">
			<el-tab-pane label="待处理" name="1"></el-tab-pane>
			<el-tab-pane label="已处理" name="2"></el-tab-pane>
		</el-tabs>
		<sw-common-frame :loading="loading">
			<el-table slot="table" size="medium" :data="tableData" height="100%">
				<el-table-column label="序号" type="index" width="48" align="center" />
				<el-table-column label="下载状态" width="90" :formatter="returnDownloadStatus" />
				<el-table-column label="资源名称" prop="pcName" min-width="240" />
				<el-table-column label="描述" prop="content" min-width="240" />
				<el-table-column label="创建人" prop="createName" min-width="120" />
				<el-table-column label="创建时间" prop="createTime" min-width="160" />
				<el-table-column label="操作" width="160" v-if="activeName === '1'">
					<template slot-scope="{ row }">
						<el-button size="medium" type="text" @click="handleLookData(row)">预览</el-button>
						<el-button size="medium" type="text" @click="handleDisposeData(row)">处理</el-button>
						<el-button size="medium" type="text" @click="handleDeleteData(row)">彻底删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<template slot="page">
				<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
			</template>
		</sw-common-frame>
	</div>
</template>

<script>
import { mapGetters } from 'vuex';
import listMixins from '@/mixins/listMixins';
import { getResInformPageList, batchUpdateResInform } from '@/api/data/tbNetReport';
export default {
	mixins: [listMixins],
	data() {
		return {
			activeName: '1',
			businessKey: '',
			flowDrawer: false
		};
	},
	computed: {
		...mapGetters(['userInfo']),
		listFunction() {
			return eval(getResInformPageList);
		},
		requestParams() {
			return { ...this.queryData, category: '1' };
		}
	},
	watch: {
		activeName: {
			handler(val) {
				this.queryData.page = 1;
				if (val === '1') {
					this.$set(this.queryData, 'auditStatus', '1');
				} else if (val === '2') {
					this.$set(this.queryData, 'auditStatus', '2,3,4');
				}
				this.queryTableData();
			},
			immediate: true
		}
	},
	methods: {
		//返回下载状态
		returnDownloadStatus(data) {
			let text = '';
			let attrs = { size: 'medium', disableTransitions: true };
			if (data.auditStatus === '1') {
				text = '待处理';
			} else if (data.auditStatus === '2') {
				text = '禁用';
				attrs['type'] = 'warning';
			} else if (data.auditStatus === '3') {
				text = '驳回';
				attrs['type'] = 'danger';
			} else if (data.auditStatus === '4') {
				text = '删除';
				attrs['type'] = 'info';
			}
			return this.$createElement('ElTag', { attrs }, text);
		},

		//预览资源
		handleLookData(data) {
			let routerData = this.$router.resolve(`/data/resource/${data.pcId}`);
			window.open(routerData.href || 'about:blank', '_blank');
		},

		//审核按钮
		handleDisposeData(data) {
			let that = this;
			let createEle = this.$createElement;
			this.$msgbox({
				title: '消息',
				message: createEle('elRadioGroup', {}, [createEle('elRadio'), createEle('elRadio')]),
				showCancelButton: true,
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				beforeClose: (action, instance, done) => {
					done();
					console.log(action, instance);
					/* if (action === 'confirm') {
						instance.confirmButtonLoading = true;
						instance.confirmButtonText = '执行中...';
						setTimeout(() => {
							done();
							setTimeout(() => {
								instance.confirmButtonLoading = false;
							}, 300);
						}, 3000);
					} else {
						done();
					} */
				}
			});
		},

		//删除下载
		handleDeleteData(data) {
			console.log(data.id);
		}
	}
};
</script>
